﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MBS.UserControls.MovieUserControl
{
    public partial class MovieList : System.Web.UI.UserControl
    {
        #region transfer

        MBSBLC.BLC movieblc = new MBSBLC.BLC();
        Dictionary<int, string> dct;

        public delegate void MovieListHandler(int SelectedValue);

        public event MovieListHandler MovieListChanged;


        private int movieID;

        public int MovieID
        {
            get { return movieID; }
            set { movieID = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                movieblc = new MBSBLC.BLC();
            }
        }
        public void LoadDropDownBox()
        {

            dct = new Dictionary<int, string>();
            dct = movieblc.GetAllMovies();
            ddlMovieList.DataSource = dct;
            ddlMovieList.DataTextField = "Value";
            ddlMovieList.DataValueField = "Key";
            ddlMovieList.DataBind();

        }

        public int GetSelectedValue()
        {
            if (ddlMovieList.SelectedValue.Equals("")) return 0;
            MovieID = Convert.ToInt32(ddlMovieList.SelectedValue);
            return MovieID;

        }

        protected void ddlMovieList_SelectedIndexChanged(object sender, EventArgs e)
        {
            MovieListChanged(GetSelectedValue());
        }

        #endregion
    }
}